<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1.0,maximum-scale=1,minimum-scale=1,user-scalable=no"
    />
    <title>20-单选框radio.html</title>
    <style>
      * {
        margin: 0;
        padding: 0;
        box-sizing: border-box;
      }
    </style>
  </head>
  <body>
    <input type="radio" name="sex" value="男" />
    男
    <input type="radio" name="sex" value="女" />
    女

    <script>
      const sex = "男";
      document.querySelector(`[name="sex"][value="${sex}"]`).checked = true;
      // 如何设置女生被选中
    </script>
  </body>
</html>
